<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <script src="/lib/jquery-1.8.3.min.js" type="text/javascript"></script>
</head>
<body class="bg-blue">
<div style="margin-top:10px">
    <label>输入最新版本：</label>
    <input type="text" id="currentVersion" name="currentVersion">
    <label>输入最新版本制作日期：</label>
    <input type="text" id="currentVersionDate" name="currentVersionDate">
</div>

<div style="margin-top:10px">
    <label>输入最新产品版本：</label>
    <input type="text" id="productVersion" name="productVersion">
    <label>输入产品上一版本：</label>
    <input type="text" id="previousVersion" name="previousVersion">
</div>
<div style="margin-top:10px">
    <label>输入最新算法版本：</label>
    <input type="text" id="coreVersion" name="coreVersion">
    <label>输入上一算法版本：</label>
    <input type="text" id="corePreviousVersion" name="corePreviousVersion">
</div>
<div style="margin-top:10px">
    <label>输入数据版本：</label>
    <input type="text" id="dataVersion" name="dataVersion">
</div>
<div style="margin-top:10px">
    <label style="float: left;">产品升级说明：</label>
    <textarea id="productContent" rows="10" cols="75" name="productContent"></textarea>

</div>
<div style="margin-top:10px">
    <label style="float: left;"> 算法升级说明：</label>
    <textarea id="coreContent" rows="10" cols="75" name="coreContent"></textarea>
</div>
<input type="button" onclick="buidJsonData()" value="生成json串">
<div id="jsonDataText" style="margin: 10px;"></div>
<script>
    function buidJsonData(){
        var currentVersion = $('#currentVersion').val();
        var previousVersion = $('#previousVersion').val();
        var currentVersionDate = $('#currentVersionDate').val();
        var productVersion = $('#productVersion').val();
        var coreVersion = $('#coreVersion').val();
        var corePreviousVersion = $('#corePreviousVersion').val();
        var dataVersion = $('#dataVersion').val();
        var coreContentInput = $('#coreContent').val();
        var productContentInput = $('#productContent').val();
        var productContentArr = productContentInput.split('\n');
        var coreContentArr = coreContentInput.split('\n');
        var data = {};
        var productContent=[];
        var coreContent=[];
        data.currentVersion = currentVersion;
        data.previousVersion = previousVersion;
        data.currentVersionDate =currentVersionDate;
        data.productVersion = productVersion;
        data.coreVersion = coreVersion;
        data.corePreviousVersion =corePreviousVersion;
        data.dataVersion =dataVersion;
        data.productContent =productContent;
        data.coreContent =coreContent;
        addCoreProductContent(coreContentArr,coreContent);
        addProductContent(productContentArr,productContent);

        $('#jsonDataText').text(JSON.stringify(data));
    }
    function addProductContent(productContentArr,productContent){
        var keyTmp;
        var chidrenTmp;
        for(var i = 0;i<productContentArr.length;i++){
            if(productContentArr[i]){
                if(productContentArr[i].indexOf("  ")==0){
                    var strTmp = productContentArr[i].replace(/ /g,"");
                    if(!chidrenTmp || chidrenTmp == ''){
                        chidrenTmp = [];
                        keyTmp.chidren =chidrenTmp;
                    }
                    var tmp = {};
                    var index = chidrenTmp.length;
                    tmp.key = productContentArr[i];
                    chidrenTmp[index] = tmp;
                }else {
                    var index = productContent.length;
                    keyTmp = {};
                    chidrenTmp='';
                    keyTmp.key = productContentArr[i];
                    productContent[index] = keyTmp;
                }
            }
        }
    }
    function addCoreProductContent(coreContentArr,coreContent){
        var keyTmp={};
        var chidrenTmp={};
        for(var i = 0;i<coreContentArr.length;i++){
            if(coreContentArr[i]){
                if(coreContentArr[i].indexOf("  ")==0){
                    var strTmp = coreContentArr[i].replace(/ /g,"");
                    if(!chidrenTmp || chidrenTmp == ''){
                        chidrenTmp = [];
                        keyTmp.chidren =chidrenTmp;
                    }
                    var tmp = {};
                    var index = chidrenTmp.length;
                    tmp.key = coreContentArr[i];
                    chidrenTmp[index] = tmp;
                }else {
                    var index = coreContent.length;
                    chidrenTmp='';
                    keyTmp = {};
                    keyTmp.key = coreContentArr[i];
                    coreContent[index] = keyTmp;
                }
            }
        }
    }
</script>
</body>
</html>